package com.jt.tenant.conn;

import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

@HttpInlet(Conn.INLET_GET_WEB_PIC)
public class GetPIC extends JTAsyGet<GetPIC.Info> {

    public String type;

    public GetPIC(AsyCallBack<Info> asyCallBack) {

        super(asyCallBack);

    }

    @Override
    protected Info parser(JSONObject object) {

        JSONObject apiTYF = object.optJSONObject("apiTYF");

        JSONObject head = apiTYF.optJSONObject("head");

        Info info = new Info();

        info.msg = head.optString("msg");

        if(info.msg.equals("000")){

            JSONObject body = apiTYF.optJSONObject("body");

            JSONArray piclist = body.optJSONArray("logo");

            if (piclist!=null) {

                for (int i = 0; i < piclist.length(); i++) {

                    PicList mList = new PicList();

                    JSONObject mpl = piclist.optJSONObject(i);

                    mList.address = mpl.optString("path");

                    mList.type = mpl.optString("type");

                    mList.url = mpl.optString("url");

                    info.picLists.add(mList);

                }

            }

        }

        return info;

    }

    public static class Info {

        public String msg;

        public List<PicList> picLists = new ArrayList<>();

    }

    public static class  PicList{

        public String address;

        public String type;

        public String url;


    }


}
